package com.demo.springMvcDemo.web;

import java.io.IOException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.demo.springMvcDemo.model.Employee;
import com.demo.springMvcDemo.service.IEmployeeService;

@Controller
@RequestMapping(value = "/employee")
public class EmployeeController {

	// @Resource
	@Autowired
	private IEmployeeService service;

	// 查询所有的
	@RequestMapping(value = "/employee", method = RequestMethod.GET)
	@ResponseBody
	public Object employee() {

		return service.queryList();

	}

	// 添加
	@RequestMapping(value = "/insert", method = RequestMethod.POST)
	@ResponseBody
	public Integer save(Employee employee) throws IOException {
		Integer num = service.insertObject(employee);
		return num;
	}

	// 修改 先根据id查询一条信息
	@RequestMapping(value = { "/toUpdate" }, method = { RequestMethod.GET, RequestMethod.POST })
	@ResponseBody
	public Object queryObject(@RequestParam(value = "id") Integer i) {
		Employee employee = service.queryObject(i);
		return employee;
	}

	// 修改
	@RequestMapping(value = "/update", method = RequestMethod.POST)
	@ResponseBody
	public Integer save2(Employee employee) {
		Integer integer = service.updateObject(employee);
		return integer;

	}

	// 删除
	@RequestMapping(value = "/delete", method = RequestMethod.GET)
	@ResponseBody
	public Integer deleteObject(Integer id) {
		Integer num = service.deleteObject(id);
		return num;
	}

}
